import flet as ft

from views.treasure_dialogs.pdf2word import Dialog as pdf2wordDialog
from views.treasure_dialogs.pdf2img import Dialog as pdf2imgDialog
from views.treasure_dialogs.img2pdf import Dialog as img2pdfDialog
from views.treasure_dialogs.imageSizeSettings import ImgDialog
from views.treasure_dialogs.clearWatermar import ClearWatermar

"""
工具主页
"""


class ViewPage(ft.Stack):
    def __init__(self, page):
        self.grid = ft.GridView(
            expand=1,
            runs_count=5,
            max_extent=150,
            child_aspect_ratio=1.0,
            spacing=10,
            run_spacing=10,
            padding=100,
        )
        self.pdf2word = ft.Stack(
            [
                ft.OutlinedButton(
                    "pdf转word",
                    icon=ft.icons.PICTURE_AS_PDF,
                    width=200,
                    height=50,
                    on_click=self.open_pdf2word,
                )
            ]
        )
        self.pdf2img = ft.Stack(
            [
                ft.OutlinedButton(
                    "pdf转img",
                    icon=ft.icons.PICTURE_AS_PDF_OUTLINED,
                    width=200,
                    height=50,
                    on_click=self.open_pdf2img,
                )
            ]
        )
        self.img2pdf = ft.Stack(
            [
                ft.OutlinedButton(
                    "img转pdf",
                    icon=ft.icons.HIDE_IMAGE,
                    width=200,
                    height=50,
                    on_click=self.open_img2pdf,
                )
            ]
        )
        self.settingImg = ft.Stack(
            [
                ft.OutlinedButton(
                    "图片大小设置",
                    icon=ft.icons.PICTURE_IN_PICTURE_OUTLINED,
                    width=200,
                    height=50,
                    on_click=self.open_setting_img,
                )
            ]
        )
        self.clearWatermar = ft.Stack(
            [
                ft.OutlinedButton(
                    "水印去除",
                    icon=ft.icons.PICTURE_IN_PICTURE_ALT_ROUNDED,
                    width=200,
                    height=50,
                    on_click=self.open_clear_watermar,
                )
            ]
        )
        self.html2md = ft.Stack(
            [
                ft.OutlinedButton(
                    "html转md",
                    icon=ft.icons.HTML_ROUNDED,
                    height=50,
                    on_click=self.open_html2md,
                )
            ]
        )
        self.grid.controls.extend(
            [self.pdf2word, self.pdf2img, self.img2pdf, self.settingImg, self.clearWatermar, self.html2md])
        super(ViewPage, self).__init__([self.grid])

    def open_pdf2word(self, e):
        self.page.dialog = pdf2wordDialog()
        self.page.update()
        self.page.dialog.open_dlg(None)

    def open_pdf2img(self, e):
        self.page.dialog = pdf2imgDialog()
        self.page.update()
        self.page.dialog.open_dlg(None)

    def open_img2pdf(self, e):
        self.page.dialog = img2pdfDialog()
        self.page.update()
        self.page.dialog.open_dlg(None)

    def open_setting_img(self, e):
        dialog = ImgDialog(self.page)  # 传递 page 参数
        self.page.add(dialog.stack)  # 将 stack 添加到页面

    def open_clear_watermar(self, e):
        dialog = ClearWatermar(self.page)  # 传递 page 参数
        self.page.add(dialog.stack)  # 将 stack 添加到页面

    def open_html2md(self, e):
        dialog = ClearWatermar(self.page)  # 传递 page 参数
        self.page.add(dialog.stack)  # 将 stack 添加到页面
